Google News
logo
jQuery - Interview Questions
What is the use of JQuery $.extend method?
Using JQuery $.extend method we can merge the contents of two or more objects into the first object. The syntax is as follow.
 
var obj-0 = $.extend({}, obj-1, obj-2);
 
Let’s we have two array’s arr-i & arr-j. During development what I need is I want to merge arr-j values to arr-i. In this case jquery extend method helps.
 
$.extend( arr-i, arr-j );
 
But this is not recursive. To merge two objects recursively we need to pass the first parameter value true to extend method. As shown in below.
 
$.extend( true, arr-i, arr-j );
Advertisement